﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrderManage
{
    public class OrderDb
    {
        [Key]
        public string OrderId { get; set; }
        [Required]
        public string  customerName { get; set; }
        [Required]
        public string orderDate { get; set; }
        [Required]
        public double money { get; set; }
        public List<OrderDetailDb> orderDetails { get; set; }

        public int CompareTo(object obj)
        {
            if (!(obj is OrderDb))
            {
                throw new NotImplementedException();
            }
            OrderDb rec = (OrderDb)obj;
            return this.OrderId.CompareTo(rec.OrderId);
        }
        public override string ToString()
        {
            string order = "";
            order += "Order ID:" + OrderId + "\n";
            order += "Customer:" + customerName + "\n";
            order += "Order Date:" + orderDate + "\n";
            order += "Details:\n" + orderDetails;
            order += "sum money:" + money;
            return order;
        }
        public override bool Equals(object obj)
        {
            OrderDb o = obj as OrderDb;
            return o != null && o.OrderId.Equals(OrderId) && o.customerName.Equals(customerName) && o.orderDetails.Equals(orderDetails) && o.money == money;
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

    }

    public class OrderDetailDb
    {
        [Key]
        public int detailId { get; set; }
        [Required]
        public string goodsName { get; set; }
        [Required]
        public double goodsPrice{ get; set; }
        [Required]
        public int goodsNumber { get; set; }

        public string orderId { get; set; }
        public OrderDb order { get; set; }

        public override string ToString()
        {
            string orderDetail = "";
            /*for (int i = 0; i < count; i++)
            {
                orderDetail += goods[i] + ":" + numbers[i] + "个" + "\n";
            }*/
            orderDetail += goodsName+"("+goodsPrice+")" + ":" + goodsNumber + "个" + "\n";
            return orderDetail;
        }
    }

    public class GoodsDb
    {
        [Key]
        public string name { get; set; }
        [Required]
        public double price { get; set; }
        public string orderId { get; set; }
        public int detailId { get; set; }
        public OrderDb order { get; set; }
        public OrderDetailDb detail { get; set; }

        
    }

    public class CustomerDb
    {
        [Key]
        public string name { get; set; }
    }
}
